package config;

import android.content.Context;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

/**
 * wechat
 *
 * @author donal
 *
 */
public class QYRestClient {

	  private static AsyncHttpClient client = new AsyncHttpClient();
	  
	  public static AsyncHttpClient getIntance() {
		  return client;
	  }

	  public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
	      client.get(getAbsoluteUrl(url), params, responseHandler);
	  }

	  public static void addcustomerget(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
			client.get(getCardUrl(url), params, responseHandler);
	  }
	  public static void addcustomer(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
			client.post(getCardUrl(url), params, responseHandler);
	  }

	  public static void getWeb(Context context, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
        client.get(context, url, params, responseHandler);
    }

	  public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
	      client.post(getAbsoluteUrl(url), params, responseHandler);
	  }

	  public static void muchPost(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
	      client.post(getMuchAbsoluteUrl(url), params, responseHandler);
	  }
	  
	  public static void post(Context context, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
	      client.post(context, getAbsoluteUrl(url), params, responseHandler);
	  }

	  public static void cardPost(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
	      client.post(getCardReaderdUrl(url), params, responseHandler);
	  }

	  public static void hospitalPost(RequestParams params, AsyncHttpResponseHandler responseHandler) {
	      client.post(CommonValue.search_sapce_info, params, responseHandler);
	  }
		public static void getChildrenSpace(RequestParams params, AsyncHttpResponseHandler responseHandler) {
			client.post(CommonValue.HC, params, responseHandler);
		}
	public static void getNFCSpace(RequestParams params, AsyncHttpResponseHandler responseHandler) {
		client.post(CommonValue.NFCHC, params, responseHandler);
	}
		public static void getfloor(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
			client.get(getAbsoluteUrl(url), params, responseHandler);
		}
		public static void printOrder(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
			client.post(getAbsoluteUrl(url), params, responseHandler);
		}
	public static void updataInfoPost(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
		client.post(getCardUrl(url), params, responseHandler);
	}
	public static void alipayQuery(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
		client.post(getAlipayQueryUrl(url), params, responseHandler);
	}

	  private static String getAbsoluteUrl(String relativeUrl) {
		  client.setTimeout(35*1000);
		  client.setMaxConnections(5);
	      return CommonValue.BASE_API + CommonValue.URL_PREFIX + relativeUrl;
	  }
	  private static String getCardReaderdUrl(String relativeUrl) {
		  client.setTimeout(35*1000);
		  client.setMaxConnections(5);
	      return CommonValue.BASE_API + CommonValue.URL_CARDREADER + relativeUrl;
	  }
	  private static String getCardUrl(String relativeUrl) {
		  client.setTimeout(35*1000);
		  client.setMaxConnections(5);
	      return CommonValue.BASE_API + CommonValue.URL_CARD + relativeUrl;
	  }
	  private static String getMuchAbsoluteUrl(String relativeUrl) {
		  client.setTimeout(240*1000);
		  client.setMaxConnections(50);
	      return CommonValue.BASE_API + CommonValue.URL_PREFIX + relativeUrl;
	  }
	private static String getAlipayQueryUrl(String relativeUrl) {
		client.setTimeout(240*1000);
		client.setMaxConnections(5);
		return CommonValue.BASE_API + CommonValue.URL_PREFIX + relativeUrl;
	}


}
